package com.xintai.sparepart.purchase.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xintai.common.annotation.Log;
import com.xintai.common.core.controller.BaseController;
import com.xintai.common.core.domain.AjaxResult;
import com.xintai.common.enums.BusinessType;
import com.xintai.sparepart.purchase.domain.BeiPurchaseFile;
import com.xintai.sparepart.purchase.service.IBeiPurchaseFileService;
import com.xintai.common.utils.poi.ExcelUtil;
import com.xintai.common.core.page.TableDataInfo;

/**
 * 合同上传文件Controller
 *
 * @author xintai
 * @date 2021-02-24
 */
@RestController
@RequestMapping("/beijiancailiao/apply/file")
public class BeiPurchaseFileController extends BaseController
{
    @Autowired
    private IBeiPurchaseFileService beiPurchaseFileService;

    /**
     * 查询合同上传文件列表
     */
    @PreAuthorize("@ss.hasPermi('beijiancailiao:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(BeiPurchaseFile beiPurchaseFile)
    {
        startPage();
        List<BeiPurchaseFile> list = beiPurchaseFileService.selectBeiPurchaseFileList(beiPurchaseFile);
        return getDataTable(list);
    }

    /**
     * 导出合同上传文件列表
     */
    @PreAuthorize("@ss.hasPermi('beijiancailiao:file:export')")
    @Log(title = "合同上传文件", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BeiPurchaseFile beiPurchaseFile)
    {
        List<BeiPurchaseFile> list = beiPurchaseFileService.selectBeiPurchaseFileList(beiPurchaseFile);
        ExcelUtil<BeiPurchaseFile> util = new ExcelUtil<BeiPurchaseFile>(BeiPurchaseFile.class);
        return util.exportExcel(list, "file");
    }

    /**
     * 获取合同上传文件详细信息
     */
    @PreAuthorize("@ss.hasPermi('beijiancailiao:file:query')")
    @GetMapping(value = "/{beiId}")
    public AjaxResult getInfo(@PathVariable("beiId") Long beiId)
    {
        return AjaxResult.success(beiPurchaseFileService.selectBeiPurchaseFileById(beiId));
    }

    /**
     * 新增合同上传文件
     */
    @PreAuthorize("@ss.hasPermi('beijiancailiao:file:add')")
    @Log(title = "合同上传文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BeiPurchaseFile beiPurchaseFile)
    {
        return toAjax(beiPurchaseFileService.insertBeiPurchaseFile(beiPurchaseFile));
    }

    /**
     * 修改合同上传文件
     */
    @PreAuthorize("@ss.hasPermi('beijiancailiao:file:edit')")
    @Log(title = "合同上传文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BeiPurchaseFile beiPurchaseFile)
    {
        return toAjax(beiPurchaseFileService.updateBeiPurchaseFile(beiPurchaseFile));
    }

    /**
     * 删除合同上传文件
     */
    @PreAuthorize("@ss.hasPermi('beijiancailiao:file:remove')")
    @Log(title = "合同上传文件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{beiIds}")
    public AjaxResult remove(@PathVariable Long[] beiIds)
    {
        return toAjax(beiPurchaseFileService.deleteBeiPurchaseFileByIds(beiIds));
    }
}
